<template>
	<view>
		<view class="image-container">
			<image :src="equip.picture" style="width: 100%;margin: 0 auto"></image>
		</view>
		<u-cell-group>
			<u-cell size="large" title="器械名称" :value="equip.equipName">
			</u-cell>
			<u-cell size="large" title="购入时间" :value="equip.purchaseTime">
			</u-cell>
			<u-cell size="large" title="器械简介" :value="equip.intro">
			</u-cell>
			<u-cell size="large" title="锻炼部位" :value="equip.partNames">
			</u-cell>
		</u-cell-group>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				equip: {}
			};
		},
		onLoad(options) {
			this.getById(options.id)
		},
		methods: {
			async getById(id) {
				let {
					data: res
				} = await uni.$http.get('/user/equip/' + id)
				if (res.code === 20000) {
					this.equip = res.data
					this.equip.partNames = this.getPartName(this.equip.partList)
				} else {
					uni.$showMsg(res.msg)
				}
			},
			getPartName(partList) {
				let partNames = []
				if (Array.isArray(partList)) {
					for (let part of partList) {
						partNames.push(part.categoryName)
					}
					// for (let i = 0; i < partList.length; i++) {
					// 	partNames.push(partList[i].categoryName)
					// }
					return partNames.toString()
				}
				return
			}
		}
	}
</script>

<style lang="scss">

</style>